package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.SendAndroidInterestShopRequest;
import keeto.com.vn.classified.response.SendAndroidInterestShopResponse;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskSendAndroidInterestShop extends AbstractTask{

	String guarantyStoreId;
	String userName;
	int isInterest;
	String type;
	String authenkey;

	public TaskSendAndroidInterestShop(ClassifiedListener listener, ClassifiedCore core,String guaranteStoreId,String userName, int isInterest,String Type, String authenKey) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.guarantyStoreId= guaranteStoreId;
		this.userName= userName;
		this.isInterest = isInterest;
		this.type = Type;
		this.authenkey = authenKey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
	IOException {
		SendAndroidInterestShopRequest request = new SendAndroidInterestShopRequest();
		request.setGuaranteStoreId(guarantyStoreId);
		request.setUserName(userName);
		request.setIsInterest(isInterest);
		request.setType(type);
		request.setAuthenKey(authenkey);
		SendAndroidInterestShopResponse response = json.sendAndroidInterestShop(request);

		for (ClassifiedListener listener : listeners){
			listener.finishSendAndroidInterestShop(response.getReturnCode());
		}

	}

	@Override
	public void timeoutCallback() {
		for (ClassifiedListener listener : listeners){
			listener.finishSendAndroidInterestShop(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502);
		}
	}

}
